package com.example.schedule.today;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.schedule.R;
import com.example.schedule.db.Plan;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import static com.example.schedule.MainActivity.count;

public class TodayEdit extends AppCompatActivity {

    private EditText mTodayEdit;
    private Button mTodayFinish;
    private String todayText;
    private Calendar mCalendar;
    private Date mDate;
    private String TAG = "TodayEdit";
    Plan today = new Plan();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_today_edit);
        initView();
        initEvent();
    }

    private void initEvent() {

        mTodayFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                todayText = mTodayEdit.getText().toString().trim();
                if (todayText != null){
                    @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy 年 MM 月 dd 日");
                    mDate = new Date();
                    String date = simpleDateFormat.format(mDate);
                    today.setId(count);
                    today.setWritePlan(todayText);
                    today.setStatus(false);
                    today.setCreateTime(date);
                    Log.d(TAG, "onClick: "+ count);
                    Log.d(TAG, "onClick: "+todayText);
                    Log.d(TAG, "onClick: "+today.isStatus());
                    Log.d(TAG, "onClick: "+date);
                    today.saveThrows();
                    count++;
                }
               finish();
            }
        });
    }

    private void initView() {
        mTodayEdit = findViewById(R.id.today_edit_text);
        mTodayFinish = findViewById(R.id.finish);
    }

}